﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static QRCoder.PayloadGenerator;

namespace Lg.Core.SMS.YM
{
    internal static class YMEntensions
    {
        public static List<BaseReply>? ToBaseReplyList(this List<YM.ReplyEntity> list)
        {
            List<BaseReply>? result =new List<BaseReply>();
            if(list != null)
            {
                foreach (var item in list)
                {
                    result.Add(new BaseReply
                    {
                        Content = item.content,
                        ExtendCode = item.extendedCode,
                        Phone = item.mobile,
                        Time = item.moTime
                    });
                }
            }
            else
            {
                result = null;
            }
            
            return result;
        }

        public static List<BaseReport>? ToBaseReportList(this List<YM.ReportEntity> list)
        {
            List<BaseReport>? result = new List<BaseReport>();
            if (list != null)
            {
                foreach (var item in list)
                {
                    var model = new BaseReport
                    {
                        CustomSmsId = Convert.ToInt64(item.customSmsId),
                        ExtendCode = item.extendedCode,
                        Phone = item.mobile,
                        FailMsg = $"[{item.state}]{item.desc}",
                        Id = item.smsId
                    };
                    if (item.state == "DELIVRD")
                    {
                        model.SendState = (int)ClientSmsSendStateOptions.Success;
                    }
                    else if (item.state == "TIMEOUT")
                    {
                        model.SendState = (int)ClientSmsSendStateOptions.Timeout;
                    }
                    else
                    {
                        model.SendState = (int)ClientSmsSendStateOptions.Fail;
                    }
                    result.Add(model);
                }
            }
            else
            {
                result = null;
            }

            return result;
        }

        public static BaseSendResult ToBaseSendResult(this YMSendResultEntity resultEntity)
        {
            return new BaseSendResult
            {
                CustomSmsId = Convert.ToInt64(resultEntity.customSmsId),
                Id = resultEntity.smsId,
                Phone = resultEntity.mobile
            };
        }       
    }
}
